<!-- 火情详情 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 48rpx;" slot="content">火情详情</block>
		</cu-custom>
		<view class="content">
			<ul>
				<li>
					<text>上报人：{{sbr}}</text>
				</li>
				<li>
					<text>联系方式：{{tel}}</text>
				</li>
				<li>
					<text>火情名称：{{name}}</text>
				</li>
				<li>
					<text>所属企业：{{enterprise}}</text>
				</li>
				<li>
					<text>详细地址：{{address}}</text>
				</li>
				<li>
					<text>火情确认时间：{{time}}</text>
				</li>
			</ul>
		</view>

		<map class="my-map" :latitude="latitude" :longitude="longitude" :markers="covers">
		</map>

		<scroll-view scroll-x class=" nav">
			<view class="flex text-center my-nav">
				<view class="cu-item flex-sub" :class="index==TabCur?'text-orange cur':'text-black'"
					v-for="(item,index) in tabs" :key="index" @tap="tabSelect" :data-id="index">
					{{item}}
				</view>
			</view>
			<view class="bg-white">
				<view style="color: red;text-align: center;" v-if="ulist.length ==0">暂无数据</view>
				<view class="fk_content" v-for="(item,index) in ulist" :key="index">
					<text>姓名：{{item.userName}}</text>
					<text>电话：{{item.phone}}</text>
					<text>状态：{{tabs[TabCur]}}</text>
					<text @click="call(item.phone)">点击拨打电话</text>
				</view>
			</view>
		</scroll-view>
		<view class="flex btns-group bg-gray">
			<!-- <button class="my-btn-grpup">视频通话</button> -->
			<button class="my-btn-grpup" @tap="showModal">火情视频</button>
			<button v-if="fireExecutionStatus===0" class="my-btn-grpup" @click="jshq">结束火情</button>
		</view>

		<view class="cu-modal" v-show="video_show" :class="video_show?'show':''">
			<view class="cu-dialog">
				<view class="bg-img" style="background-color: #C7C7C7;">

					<view class="cu-bar   text-white">
						<text style="margin-left: 20rpx;">视频监控</text>
						<view style="margin-right: 20rpx;" @tap="hideModal">
							<text style="" class="cuIcon-close "></text>
						</view>
					</view>
					<view style="background-color: #FFFFFF;height: 100%">
						<video style="margin: 20px 0;" :src="video_url" enable-danmu danmu-btn controls></video>
					</view>
				</view>
			</view>
		</view>

		<view class="cu-modal" :class="model">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">
					<button class="cu-btn text-blue" @click="hqcancle">取消</button>
					<button class="cu-btn text-green" @click="tjjshq">确定</button>
				</view>
				<view class="padding-xl">
					如火情未扑灭，恶意结束火情信息将承担相应法律责任
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import * as constants from '@/common/config.js';
	export default {
		data() {
			return {
				sbr: '',
				tel: '',
				name: '',
				enterprise: '',
				address: '',
				time: '',

				id: 0, // 使用 marker点击事件 需要填写id
				title: 'map',
				latitude: 39.909,
				longitude: 116.39742,
				covers: [],
				TabCur: 0,
				scrollLeft: 0,
				tabs: ['已反馈', '未反馈'],
				fk_name: '',
				fk_tel: '',
				modalName: null,
				video_url: '',
				video_show: false,
				ulist: [],
				ucId: '',
				fireExecutionStatus: '',
				model: '',
				imgUrl:''
			}
		},
		methods: {
			hqcancle() {
				this.model = ''
			},
			call(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				});
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
				this.fk()
			},
			showModal(e) {
				this.video_show = true
			},
			hideModal(e) {
				this.video_show = false
			},
			// 火情通知人
			fk() {
				let that = this
				// 封装参数
				let params = {
					"fireId": that.ucId,
					"status": that.TabCur
				}

				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/fireInfo/getFireNoticeUserList',
					data: {
						...params
					}
				}).then(function(res) {
					that.ulist = res.data.data
				}).catch(function(e) {

				})
			},
			jshq() {
				this.model = 'show'
			},
			tjjshq() {
				// 首先拍照片
				let that = this
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相册选择
					success: (res) => {
						let path = res.tempFilePaths
						
						// 上传
						let app = getApp()
						let token = app.globalData.getToken('authorization')
						uni.uploadFile({
							url: constants.API + 'wx/common/upload',
							filePath: this.videoPath,
							header: {
								"authorization": token
							},
							name: 'file',
							success: (uploadFileRes) => {
								
								that.imgUrl = uploadFileRes.data.data
								
								// 封装参数
								let params = {
									"ucId": that.ucId,
									"confirmFireFile":that.imgUrl
								}
								// 请求数据
								let app = getApp()
								app.globalData.request({
									url: 'wx/firemanage/generateFireFinishPutFire',
									data: {
										...params
									}
								}).then(function(res) {
									console.info(res)
									
									if (res.data.code == 0) {
										uni.navigateBack({
											delta: 2
										})
									}
									

								
								}).catch(function(e) {
									uni.showToast({
										title: '操作失败',
										icon: 'error'
									})
								})
							}
						});
						
					}
				});
				
				
				
			},
			xq(id) {
				let that = this
				// 封装参数
				let params = {
					"ucId": that.ucId
				}
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/fireInfo/getFireInfo',
					data: {
						...params
					}
				}).then(function(res) {
					console.info(res)
					that.sbr = res.data.data.userName
					that.tel = res.data.data.userPhone
					that.name = res.data.data.name
					that.enterprise = res.data.data.enterpriseName
					that.address = res.data.data.loaction
					that.time = res.data.data.fireConfirmTime
					that.latitude = res.data.data.userLatitude
					that.longitude = res.data.data.userLongitude
					that.covers = [{
						id:Math.ceil(Math.random()*100),
						width:32,
						height:32,
						latitude: that.latitude,
						longitude: that.longitude ,
						iconPath: '../../static/test/localtion.png',
						label:{
							content:'第一报警人'+res.data.data.userName,
							borderColor:'#D90000',
							color:'#D90000',
							borderWidth:1,
							borderRadius:2,
							padding:2
						}
					}]
					that.fk_name = res.data.data.userName
					that.fk_tel = res.data.data.userPhone


					that.video_url = res.data.data.fireVodie
					that.fireExecutionStatus = res.data.data.fireExecutionStatus

				}).catch(function(e) {

				})
			}
		},
		onLoad(option) {
			this.ucId = option.ucId
			this.fk()
			this.xq()
		}
	}
</script>

<style scoped>
	page {
		width: 100vw;
	}

	.content {
		margin-top: 24rpx;
		background-color: #FFFFFF;
	}

	ul li {
		list-style: none;
		margin: 0;
		padding: 0;
		margin-left: 24rpx;
		position: relative;
	}

	li text {
		font-size: 24rpx;
		color: #777777;
		line-height: 94rpx;
	}

	li::after {
		content: ''; // 必须
		position: absolute;
		left: 2rpx;
		bottom: 0;
		right: 2rpx;
		height: 1px;
		background-color: #dcdcdc;
	}

	.my-map {
		width: 100%;
		margin-top: 20rpx;
	}

	.my-nav {
		background: #f5f6f8;
	}

	.text-black {
		color: #777777;
	}

	.fk_content {
		padding-top: 32rpx;
		display: flex;
		flex-direction: column;
		font-size: 24rpx;
		color: #777777;
		line-height: 50rpx;
		margin-left: 76rpx;
	}

	.fk_content text:last-child {
		color: #0081FF;
	}

	.btns-group {
		position: sticky;
		bottom: 0;
		margin-top: 30rpx;
		width: 100%;
		text-align: center;
		display: flex;
		flex-direction: row;
		align-items: flex-end;
	}

	.btns-group button:first-child {
		background-color: #458DF5;
		color: #FFFFFF;
		flex: 1;
		font-size: 36rpx;
		outline: none;
		border: none;
		margin: 0;
		padding: 0;
		border: 1px solid transparent;
		border-radius: 0;
		border-top-left-radius: 16px;
	}

	.btns-group button:nth-child(2) {
		background-color: #54BE7A;
		color: #FFFFFF;
		flex: 1;
		font-size: 36rpx;
		outline: none;
		border: none;
		margin: 0;
		padding: 0;
		border: 1px solid transparent;
		border-radius: 0;
	}

	.btns-group button:last-child {
		background-color: #FABD50;
		flex: 1;
		color: #FFFFFF;
		font-size: 36rpx;
		outline: none;
		border: none;
		margin: 0;
		padding: 0;
		border: 1px solid transparent;
		border-radius: 0;
		border-top-right-radius: 16px;
	}
</style>
